package com.epoint.androidphone.mobileoa.ui.syn;

import java.util.HashMap;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.epoint.androidmobile.bizlogic.dbservice.ConfigKey;
import com.epoint.androidmobile.bizlogic.syn.task.SynTask;
import com.epoint.androidmobile.core.date.DateUtil;
import com.epoint.androidphone.R;
import com.epoint.androidphone.mobileoa.ui.superview.SuperPhonePage;

/**
 * @author liyc
 * @time 2013-5-10 上午10:36:17
 * @annomation 数据同步
 */
public class SynView extends SuperPhonePage {
	
	Button btSyn;
	TextView tvSynTime;
	long synDataTaskId;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addContentViewAndTitle(R.layout.synview, getIntentViewTitle());
		btSyn = (Button) findViewById(R.id.btSyn);
		tvSynTime = (TextView) findViewById(R.id.tvSynTime);
		btSyn.setOnClickListener(this);
		tvSynTime.setText(dbUtil.getConfigValue(ConfigKey.dsTime));
		
	}
	
	@Override
	public void onClick(View v) {
		super.onClick(v);
		if(v==btSyn)
		{
			showDialogMiddle("正在同步数据...");
			HashMap<String, Object> param = getPassMap();
			param.put("ParentOUGuid", "");
			synDataTaskId = new SynTask(this, param).startTask();
		}
	}
	
	@Override
	public void refreshUI(long taskId, Object obj) {
		super.refreshUI(taskId, obj);
		if(taskId==synDataTaskId)
		{
			boolean status = (Boolean) obj;
			if(status)
			{
				tvSynTime.setText(dbUtil.getConfigValue(ConfigKey.dsTime));
			}
		}
	}
}
